package HuaweiOD;

import java.util.Arrays;
import java.util.Scanner;

public class 第k个排列 {
    static int[] fact;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt();
        fact = new int[n + 1];

        fact[1] = 1;
        for (int i = 2; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = i + 1;
        }
        System.out.println(solve(n, k, arr));
    }

    private static String solve(int n, int k, int[] arr) {
        if (k == 1) return "1";
        int f = fact[n - 1];
        int p = arr[(k - 1) / f];
        k %= f;
        if (k == 0) k = f;
        
        arr = Arrays.stream(arr).filter(cur -> cur != p).toArray();
        if (k == 1){
            StringBuilder builder = new StringBuilder();
            for (int i : arr) {
                builder.append(i);
            }
            return p + builder.toString();
        }
        return p + solve(n - 1, k, arr);
    }
}
